<template>
  <div>
    <div class="feedback_box">
      <div>
        <i class="icon-fanhui go_back" @click="goBack" style="cursor: pointer"></i>
        <span class="title">我的工单</span>
        <el-button type="primary" size="small" plain style="position: absolute; right: 30px;top: 20px"
                   @click="addFeedback">新建工单
        </el-button>
      </div>
      <div class="operation">
        <span>状态：</span>
        <el-select v-model="status" placeholder="请选择" size="small">
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-input v-model="searchVal" prefix-icon="el-icon-search" placeholder="请输入内容" size="small"
                  style="width: 380px;margin-left: 20px" class="search" @keyup.enter.native="search"></el-input>
      </div>

      <el-table
        :data="tableData"
        :height="tableHeight"
        :cell-style="isClose"
        style="width: 100%">
        <el-table-column
          prop="orderNo"
          label="编号">
        </el-table-column>
        <el-table-column
          prop="title"
          label="标题">
          <template slot-scope="scope">
            <span @click="rowClick(scope.row)" class="feedbakc_title">{{scope.row.title}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="orderType"
          label="类别">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="创建时间"
          width="180">
        </el-table-column>
        <el-table-column
          prop="name"
          width="80"
          label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.orderStatus == 0" style="color:#2A97F9">未受理</span>
            <span v-if="scope.row.orderStatus == 1">受理中</span>
            <span v-if="scope.row.orderStatus == 2">已关闭</span>
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="优先级">
          <template slot-scope="scope">
            <span v-if="scope.row.orderLevel == '0'">普通</span>
            <span v-if="scope.row.orderLevel == '1'">紧急</span>
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="操作">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="删除" placement="top" v-if="scope.row.orderStatus == 2">
              <span>
                <i class="icon-delete_icon" style="cursor: pointer" @click.stop="beforDelete(scope.row.id)"></i>
              </span>
            </el-tooltip>
            <i class="icon-delete_icon" style="color: #dddddd" v-else></i>
          </template>

          <div slot="empty">
            <div>
              <img :src="empty" alt="" style="width: 250px"/>
            </div>
          </div>

        </el-table-column>
      </el-table>

      <el-pagination
        align="right"
        class="fixed"
        v-show="total>0"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageNo"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="pageSize"
        layout="prev, pager, next, sizes"
        :total="total">
      </el-pagination>

      <el-dialog
        :visible.sync="deleteDia"
        center
        width="30%">
        <span slot="title" class="dialog-title">删除工单提醒</span>
        <p style="text-align: center">您确定要删除这个工单吗？</p>
        <span slot="footer" class="dialog-footer">
          <el-button @click="deleteDia = false" size="small">取 消</el-button>
          <el-button type="primary" @click="deleteFeedback" size="small">确 定</el-button>
        </span>
      </el-dialog>


    </div>
  </div>
</template>

<script>
    import {myWorkOrder, deleteWorkOrder} from '@/api/feedback'

    export default {
        name: "myFeedback",
        data() {
            return {
                empty: './img/empty.png',
                tableData: [],
                pageNo: 1,
                pageSize: 10,
                total: 0,
                status: '',
                statusOptions: [
                    {
                        value: '0',
                        label: '未受理'
                    },
                    {
                        value: '1',
                        label: '受理中'
                    },
                    {
                        value: '2',
                        label: '已关闭'
                    },
                    {
                        value: '-1',
                        label: '全部'
                    }
                ],
                searchVal: '',
                deleteDia: false,
                deleteId: '', // 要删除的id
                screenHeight: document.documentElement.clientHeight,
                tableHeight: document.documentElement.clientHeight - 260
            }
        },
        created() {
            this.init()
        },
        mounted() {
            window.onresize = () => {
                this.$nextTick(() => {
                    this.screenHeight = document.documentElement.clientHeight
                    this.tableHeight = this.screenHeight - 260
                })
            }
        },
        methods: {
            init() {
                myWorkOrder(this.pageNo, this.pageSize, this.searchVal, this.status).then(res => {
                    if (res.data.success) {
                        this.tableData = res.data.data.records
                        this.total = res.data.data.total
                    }
                })
            },
            isClose({row}) {
                if (row.orderStatus == 2) {
                    return {
                        color: '#8C8C8C'
                    }
                }
            },
            handleSizeChange(size) {
                this.pageSize = size
                this.init()
            },
            handleCurrentChange(page) {
                this.pageNo = page
                this.init()
            },
            addFeedback() {
                this.$router.push('/feedback/addFeedback')
            },
            rowClick(item) {
                this.$router.push(`/feedback/userFeedback/${item.id}`)
            },
            beforDelete(id) { // 删除之前
                this.deleteDia = true
                this.deleteId = id
            },
            search() { // 搜索
                this.pageNo = 1
                this.init()
            },
            deleteFeedback() { // 删除工单
                this.deleteDia = false
                deleteWorkOrder(this.deleteId).then(res => {
                    if (res.data.success) {
                        this.$message({
                            type: 'success',
                            message: res.data.msg
                        })
                        this.init()
                    }
                })
            },
            goBack() { // 返回上一级
                this.$router.go(-1)
            }
        },
        watch: {
            status() {
                this.pageNo = 1
                this.init()
            }
        }
    }
</script>

<style scoped lang="scss">
  .go_back {
    font-size: 25px !important;
    color: #2A97F9;
  }

  .operation {
    padding: 20px 0;
  }

  .title {
    font-size: 18px;
    font-weight: 600;
    color: #435B77;
    margin-left: 10px;
  }

  .feedbakc_title {
    color: #2A97F9;
    cursor: pointer;
  }

  .feedback_box {
    background-color: white;
    padding: 25px 30px;
    position: relative;
    font-size: 13px;
    margin-bottom: 25px;
  }
</style>
